//compose 代码组合
var compose = function (f,g){
    return function(x){
        return f(g(x))
    }
}

var toUpperCase = function(x){
    return x.toUpperCase()
}

var exclaim = function(x){
    return x + '!'
}

var shout = compose(toUpperCase,exclaim)
shout('hello world')
// g优先于f执行，形成从右到左的数据流

// compose的结合律
// compose(toUpperCase,compose(head,reverse))等同于compose(compose(toUpperCase,head),reverse)
/**
    利用结合律，可以自由为组合分组
    var loudLastUpper = compose(exclaim, toUpperCase, head, reverse);
    或
    var last = compose(head, reverse);
    var loudLastUpper = compose(exclaim, toUpperCase, last);
    或
    var last = compose(head, reverse);
    var angry = compose(exclaim, toUpperCase);
    var loudLastUpper = compose(angry, last);
 */

//pointfree 模式
// 非 pointfree，因为提到了数据：word
var snakeCase = function (word) {
    return word.toLowerCase().replace(/\s+/ig, '_');
  };
// pointfree
var snakeCase = compose(replace(/\s+/ig, '_'), toLowerCase);//不显式使用参数

//实现compose的五种方式
//1.面向过程
